using FluentNHibernate.Mapping;
using Webshop20.Domain.Customers.Core;


namespace Webshop20.Infrastructure.Persistence.NH.Mappings
{
    public class CustomerMapping : ClassMap<Customer>
    {
        public CustomerMapping()
        {
            WithTable("Customers");
            Id(x => x.Id)
                .GeneratedBy
                .Increment();
            Map(x => x.EMail);
            Map(x => x.FirstName);
            Map(x => x.LastName);
            Map(x => x.RegistrationDate);
            Map(x => x.State).CustomTypeIs(typeof(int));
            Component(x => x.Adress, y =>
            {
                y.Map(z => z.City);
                y.Map(z => z.Country);
                y.Map(z => z.PostalCode);
                y.Map(z => z.Street);

            });

            References(x => x.Payment)
                .LazyLoad()
                .FetchType
                .Join()
                .Cascade
                .All();
            
            //HasOne(x => x.Payment)
            //    .FetchType
            //    .Join()
            //    .Cascade
            //    .All();
            

        }
    }
}